home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 2002 November / SGI IRIX 6.5 Applications 2002 November.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / dns / resolver-config.frm.z / resolver-config.frm
Encoding:
Text File  |  2002-06-12  |  10.0 KB  |  282 lines

  1. #!/usr/bin/perl5
  2. #
  3. # resolver-config.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: resolver-config.frm,v 1.27 1997/12/24 00:22:15 jrw Exp $
  21.  
  22. BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; }
  23. require "/usr/OnRamp/lib/OnRamp.pm";
  24. require "/usr/OnRamp/lib/java.pm";
  25.  
  26. $query = new CGI;
  27.  
  28. $help_page = "resolver-config-help.html";
  29. $resolv_cf = "/etc/resolv.conf";
  30. $title = "Name Resolver";
  31.  
  32. @order = ("nis", "bind", "local", "none");
  33.  
  34. $has_nsd = true if (-e "/usr/etc/nsd");
  35.  
  36. $js =
  37. "$js_standard
  38. $js_error_box
  39. $js_help
  40. $js_ip
  41. $js_hostname
  42. function checkForm(form) {
  43.    if (!testNameServer(form.nmsrv1) 
  44.       || !testNameServer(form.nmsrv2) 
  45.       || !testNameServer(form.nmsrv3)) return (false);
  46.    if (!testHostname(form.dmsrch1, form.dmsrch1.value, \"domain name\", 1) 
  47.       || !testHostname(form.dmsrch2, form.dmsrch2.value, \"domain name\", 1) 
  48.       || !testHostname(form.dmsrch3, form.dmsrch3.value, \"domain name\", 1) 
  49.       || !testHostname(form.dmsrch4, form.dmsrch4.value, \"domain name\", 1) 
  50.       || !testHostname(form.dmsrch5, form.dmsrch5.value, \"domain name\", 1) 
  51.       || !testHostname(form.dmsrch6, form.dmsrch6.value, \"domain name\", 1)) 
  52.          return (false);
  53.    return (true);
  54. }
  55. function testNameServer(Ctrl) {
  56.    if (Ctrl.value == \"\") return (true);
  57.    if (!testIPaddress(Ctrl.value,false)) { 
  58.       errorBox (Ctrl, \"The name server address \" 
  59.          + Ctrl.value + \"\\nis invalid.\"); 
  60.       return (false); 
  61.    }
  62.    return (true);
  63. }";
  64.  
  65. print $query->header;
  66.  
  67. if (-r $resolv_cf) { &get_resolv; }
  68.  
  69. if ($query->param) { 
  70.     $help = $document_root . $ENV{"SCRIPT_NAME"};
  71.     $help =~ s/cgi$/hlp/;
  72.     exec $help if ($query->param('help') eq "Help");
  73.  
  74.     if ($query->param('doit') eq 'Ok') {
  75.         &formValidation; 
  76.         &makeChanges; }
  77. }
  78.  
  79. &generic;
  80.  
  81. sub formValidation {
  82.     my($count, $which);
  83.  
  84.     foreach $count (1..3) {
  85.         $which = $query->param("nmsrv$count");
  86.         &error("Invalid name server IP address #$count.")
  87.             if $which && &check_ipaddr($which); 
  88.     }
  89.  
  90.     foreach $count (1..6) {
  91.         $which = $query->param("dmsrch$count");
  92.         &error("Invalid domain name #$which.") 
  93.             if $which && &check_hostname($which);
  94.     }
  95. }
  96.  
  97. sub error {
  98.     &error_block($_[0]);
  99.     &generic;
  100.     exit 0;
  101. }    
  102.  
  103. sub makeChanges {
  104.     $message = "The requested changes have been made.";
  105.  
  106.     open(OUT,"> $resolv_cf");
  107.     print OUT "search ",$query->param('dmsrch1')," ",
  108.         $query->param('dmsrch2')," ",$query->param('dmsrch3')," ",
  109.         $query->param('dmsrch4')," ",$query->param('dmsrch5')," ",
  110.         $query->param('dmsrch6'),"\n";
  111.     if (! $has_nsd) { 
  112.         print OUT "hostresorder";
  113.         if ($query->param('hres1') ne 'none') 
  114.             { print OUT " ", $query->param('hres1'); }
  115.         if ($query->param('hres2') ne 'none') 
  116.             { print OUT " ", $query->param('hres2'); }
  117.         if ($query->param('hres3') ne 'none') 
  118.             { print OUT " ", $query->param('hres3'); }
  119.         print OUT "\n";
  120.     }
  121.     print OUT "\n";
  122.     if ($query->param('nmsrv1')) { 
  123.         print OUT "nameserver ",$query->param('nmsrv1'),"\n"; }
  124.     if ($query->param('nmsrv2')) { 
  125.         print OUT "nameserver ",$query->param('nmsrv2'),"\n"; }
  126.     if ($query->param('nmsrv3')) { 
  127.         print OUT "nameserver ",$query->param('nmsrv3'),"\n"; }
  128.     close(OUT);
  129. }
  130.  
  131. sub get_resolv {
  132.     $havenfs = system ("/etc/havenfs");
  133.     if ($havenfs == 0) { @ch_order = ("bind","local","none","none"); }
  134.     else { @ch_order = ("nis","bind","local","none"); }
  135.     open(RESOLV, $resolv_cf);
  136.     while (<RESOLV>) {
  137.         next if (/^\s*[#\n]/);
  138.         chop;
  139.         @entlist = split(/\s+/);
  140.         if ($entlist[0] eq "hostresorder" && (! $has_nsd)) {
  141.             @ch_order = ("none","none","none","none");
  142.             for ($i = 1; $i <= $#entlist; $i++) {
  143.                 if ( ($entlist[$i] ne "nis") && ($entlist[$i] ne "bind") &&
  144.                      ($entlist[$i] ne "local") ) {
  145.                     print "<p>Illegal option $entlist[$i] in $resolv_cf.";
  146.                     if ($havenfs == 0) { 
  147.                         @ch_order = ("bind","local","none","none"); 
  148.                     } else { @ch_order = ("nis","bind","local","none"); }
  149.                     last;
  150.                 }
  151.                 if ( ($entlist[$i] eq "nis") && ($havenfs != 0) ) {
  152.                     $shift_list = 1; 
  153.                     next;
  154.                 }
  155.                 $ch_order[$i-1] = $entlist[$i];
  156.             }
  157.             shift @ch_order if ($shift_list);
  158.         }
  159.         elsif ($entlist[0] eq "nameserver") {
  160.             $nmserver[$#nmserver+1] =  $entlist[1];
  161.         }
  162.         elsif ($entlist[0] eq "domain") {
  163.             $dmname = $entlist[1];
  164.         }
  165.         elsif ($entlist[0] eq "search") {
  166.             for ($i = 1; $i <= $#entlist, $i <= 6; $i++) {
  167.                 $dmsearch[$i-1] =  $entlist[$i];
  168.             }
  169.         }
  170.         else {
  171.             print "<p>Illegal option $entlist[0] in $resolv_cf.";
  172.             last;
  173.         }
  174.     }
  175.     close(RESOLV);
  176. }  
  177.  
  178. sub generic {
  179.     &js_title_block($title,$js);
  180.     &header_block($title);
  181.  
  182.     print $query->startform("POST", "", "", "NAME=StandardForm", "onSubmit=\"return runSubmit()\"");
  183.  
  184.     print "<i>$message</i>";
  185.  
  186.     if (! $has_nsd) {
  187.         print "<h3>Order of services for name and address resolution:</h3>\n";
  188.  
  189.         print "<font size=\"+1\"><center><table cellpadding=5 width=450>\n";
  190.         print "<tr><th>First<th>Next<th>Last</tr>\n";
  191.     
  192.         print "<tr><td align=center>", $query->popup_menu(-name=>'hres1',
  193.                             -values=>\@order,
  194.                             -default=>$ch_order[0]);
  195.         print "\n<td align=center>", $query->popup_menu(-name=>'hres2',
  196.                             -values=>\@order,
  197.                             -default=>$ch_order[1]);
  198.         print "\n<td align=center>", $query->popup_menu(-name=>'hres3',
  199.                             -values=>\@order,
  200.                             -default=>$ch_order[2]);
  201.         print "</tr></table></center>";
  202.     }
  203.  
  204.     print "<h3>Addresses of DNS servers to do name resolution: </h3><center>";
  205.  
  206.     print "<table cellpadding=5 width=450>\n";
  207.  
  208.     print "<tr><td align=center><strong>1</strong> ",
  209.           $query->textfield(-name=>'nmsrv1',
  210.                 -default=>$nmserver[0],
  211.                 -size=>13,
  212.                 -maxlength=>16);
  213.     print "\n<td align=center><strong>2</strong> ",
  214.           $query->textfield(-name=>'nmsrv2',
  215.                 -default=>$nmserver[1],
  216.                 -size=>13,
  217.                 -maxlength=>16);
  218.     print "\n<td align=center><strong>3</strong> ",
  219.           $query->textfield(-name=>'nmsrv3',
  220.                 -default=>$nmserver[2],
  221.                 -size=>13,
  222.                 -maxlength=>16);
  223.     print "\n</tr>";
  224.     print "</table></center></font>";
  225.  
  226.     print "<p>\n";
  227. #    print "The Search list for host-name lookup can be specified below.\n",
  228. #      "The search list is normally determined from the local domain name\n",
  229. #      "by default, it begins with the local domain name, then successive\n",
  230. #      "parent domains that have at least two components in their names.\n",
  231. #      "This can be changed by listing the desired domain search path\n",
  232. #      "following the search keyword with spaces or tabs separating the names.\n",
  233. #      "Most resolver queries are attempted using each component of the search\n",
  234. #      "path in turn until a match is found.  This process can be slow and\n",
  235. #      "generates a lot of network traffic if the servers for the listed\n",
  236. #      "domains are not local.  Queries time out if no server is available for\n",
  237. #      "one of the domains.  The search list is limited to six domains with a\n",
  238. #      "total of 256 characters.  The first item in the list becomes the\n",
  239. #      "default domain name, the remaining items are the other domains to\n",
  240. #      "search after the default one.\n";
  241.  
  242.     print "<h3>List of domains that DNS servers will search:</h3>\n";
  243.     print "<font size=\"+1\"><center><table  cellpadding=5 width=450>\n";
  244.     print "<tr><td align=center><strong>1</strong> ",
  245.           $query->textfield(-name=>'dmsrch1',
  246.                 -default=>$dmsearch[0],
  247.                 -size=>13,
  248.                 -maxlength=>16);
  249.     print "\n<td align=center><strong>2</strong> ",
  250.           $query->textfield(-name=>'dmsrch2',
  251.                 -default=>$dmsearch[1],
  252.                 -size=>13,
  253.                 -maxlength=>16);
  254.     print "\n<td align=center><strong>3</strong> ",
  255.           $query->textfield(-name=>'dmsrch3',
  256.                 -default=>$dmsearch[2],
  257.                 -size=>13,
  258.                 -maxlength=>16),
  259.           "</tr>";
  260.     print "\n<tr><td align=center><strong>4</strong> ",
  261.           $query->textfield(-name=>'dmsrch4',
  262.                 -default=>$dmsearch[3],
  263.                 -size=>13,
  264.                 -maxlength=>16);
  265.     print "\n<td align=center><strong>5</strong> ",
  266.           $query->textfield(-name=>'dmsrch5',
  267.                 -default=>$dmsearch[4],
  268.                 -size=>13,
  269.                 -maxlength=>16);
  270.     print "\n<td align=center><strong>6</strong> ",
  271.           $query->textfield(-name=>'dmsrch6',
  272.                 -default=>$dmsearch[5],
  273.                 -size=>13,
  274.                 -maxlength=>16);
  275.     print "\n</tr></table></center><br>";
  276.  
  277.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"',
  278.       "onClick=\"do_help('$help_page'); return (false)\"");
  279.  
  280.     print $query->endform;
  281. }
  282.